package com.dzqc.fly.controller.pc;

import com.dzqc.fly.db.pojo.CollegePojo;
import com.dzqc.fly.db.pojo.PcUserPojo;
import com.dzqc.fly.db.pojo.SecretarySumPojo;
import com.dzqc.fly.service.FlyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**
 * 用户pc端启动jsp登录用
 */
@RestController
@RequestMapping("/")
@Slf4j
@EnableAutoConfiguration
public class FlyController {

    @Autowired
    private FlyService flyService;

    @RequestMapping(value="/")
    public ModelAndView index(){
        ModelAndView mv = new ModelAndView();
        mv.addObject("message","启动jsp登录页面");
        mv.setViewName("login");
        log.info("以进入pc端首页");
        return mv;
    }



    @RequestMapping(value="/index")
    public ModelAndView login(HttpServletRequest request){
        HttpSession session   =   request.getSession();

         String sno=String.valueOf(session.getAttribute("userSon"));
        String passWord=String.valueOf(session.getAttribute("passWord"));
        String roles=String.valueOf(session.getAttribute("roles"));

        System.out.println("sno====="+sno);

        List<SecretarySumPojo> collegePojoColname =new ArrayList<>();
        List<SecretarySumPojo> collegePojoCname =new ArrayList<>();

        /*判断权限状态，根据不同的权限状态来找不同的SQL*/

        System.out.println("roles====="+roles);
        if (roles.equals("[辅导员]")){
           // collegePojo =flyService.queryFdyid(sno,passWord);
         //   System.out.println("classPojo========="+ collegePojo);
            collegePojoColname =flyService.queryColname(Integer.valueOf(sno));
            System.out.println("classPojoColname========="+ collegePojoColname);
            collegePojoCname =flyService.queryCname(Integer.valueOf(sno));



            System.out.println("classPojoCname========="+ collegePojoCname);

        }
        else if (roles.equals("[3]")){
           /* collegePojo =flyService.queryFdyid(sno,passWord);*/

        }
        else{

        }
        ModelAndView mv = new ModelAndView();
        mv.addObject("message","启动jsp登录页面");
        mv.setViewName("index");

        mv.addObject("collegePojoColname",collegePojoColname);
        mv.addObject("collegePojoCname",collegePojoCname);

        log.info("以进入pc端首页index.jsp");
        return mv;
    }

    @RequestMapping(value="/index/list")
    public ModelAndView indexList(HttpServletRequest request){
        /*HttpSession session   =   request.getSession();

        String sno=String.valueOf(session.getAttribute("userSon"));
        String passWord=String.valueOf(session.getAttribute("passWord"));
        String roles=String.valueOf(session.getAttribute("roles"));*/

        String classId=request.getParameter("classId");


        System.out.println(classId+"____________classId___________");

        List<SecretarySumPojo> collegePojoColname =new ArrayList<>();
        List<SecretarySumPojo> collegePojoCname =new ArrayList<>();

        /*判断权限状态，根据不同的权限状态来找不同的SQL*/


        ModelAndView mv = new ModelAndView();
        mv.addObject("message","启动jsp登录页面");
        mv.setViewName("list");

        mv.addObject("collegePojoColname",collegePojoColname);
        mv.addObject("collegePojoCname",collegePojoCname);

        log.info("以进入pc端首页index.jsp");
        return mv;
    }





    @RequestMapping(value="/swiper")
    public ModelAndView swiper(){
        ModelAndView mv = new ModelAndView();
        mv.addObject("message","进入轮播图页面");
        mv.setViewName("swiper");
        log.info("进入轮播图页面");
        return mv;
    }

    @RequestMapping(value="/upload")
    public ModelAndView fileinput(){
        ModelAndView mv = new ModelAndView();
        mv.addObject("message","图片上传");
        mv.setViewName("upload");
        log.info("图片上传");
        return mv;
    }

    @RequestMapping(value="/leaveupload")
    public ModelAndView leaveupload(){
        ModelAndView mv = new ModelAndView();
        mv.addObject("message","学生请假测试");
        mv.setViewName("leaveupload");
        log.info("学生请假测试");
        return mv;
    }
}
